<?php

namespace App\Http\Controllers\back;

use App\Model\flow;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class flowingController extends Controller
{
    public function show(){
//        $pictures = flow::all();
        $pictures = DB::table('flows')->paginate(3);
        return view('back.writeruser.flowing',compact('pictures'));
    }
    //上传新的图片并更换
    public function swap(Request $request)
    {
        if($request->isMethod('post')){
            $png = flow::find($request->id);
            if($request->icon){
                $png = unlink(public_path().'/box/'.$request->id.'.png');
                    $name = $request->id . '.png';
                    $dir = public_path() . '/box/';
                    $request->icon->move(public_path() . '/box/', $name);
                    $upnew = flow::find($request->id);
                    $upnew->addtime = time();
                    $upnew->save();
            }
            return redirect('back/writer/flowing');
        }
        $pictures = flow::all();
        return view('back.writeruser.flowing',compact('pictures'));
    }

}
